import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/*这个程序用来练习线程安全的HashMap*/
public class MapTest {
    public MapTest() {
        Map<String, Integer> map = new HashMap<>();
        map.put("王启越", 100);
        map.put("王越", 300);
        map.put("王启", 500);
        MapRunnable r1 = new MapRunnable(map);
        MapRunnable r2 = new MapRunnable(map);
        new Thread(r1).start();
        new Thread(r2).start();
    }

    public static void main(String[] args) {
        new MapTest();
    }
}

class MapRunnable implements Runnable {
    public MapRunnable(Map<String, Integer> map) {
        this.map = map;
    }

    @Override
    public void run() {
        while (true) {
            for (Map.Entry entry : map.entrySet()) {
                System.out.println(entry.getKey() + "" + entry.getValue());
            }
        }
    }

    Map<String, Integer> map;

}
